import { Image } from '@tarojs/components';
import React from 'react';
import Icon from '../Icon';
import Imagelocation from '../Imagelocation';

/**
 * 必填参数: name size src
 * name 存在, 则为 Icon
 * type 存在, 则为 Imagelocation
 * 否则 为 Image
 * @param {*} o
 * @param {string} o.className
 *
 * @param {string} o.name Icon的name
 * @param {string} o.size Icon的size
 * @param {string} o.color Icon的color
 *
 * @param {string} o.type Imagelocation的type
 * @param {string} o.src Imagelocation/Image的 url
 *
 * @returns
 */
const ImageOrIcon = ({ name, type, ...rest }) => {
  if (name) {
    return (
      <Icon
        {...{
          name,
          ...rest,
        }}
      />
    );
  }

  if (type) {
    return <Imagelocation type={type} {...rest} />;
  }

  return <Image {...rest} />;
};

export default ImageOrIcon;
